package cn.juan;
import java.util.Scanner;

class Person{
    private String name;
    private boolean sex;
    private int age;
    private boolean isMarried;
    private Person object;

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", sex=" + sex +
                ", age=" + age +
                ", isMarried=" + isMarried +
                ", object=" + object +
                '}';
    }

    public Person(String name, boolean sex, int age, boolean isMarried) {
        this.name = name;
        this.sex = sex;
        this.age = age;
        this.isMarried = isMarried;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean isSex() {
        return sex;
    }

    public void setSex(boolean sex) {
        this.sex = sex;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public boolean isMarried() {
        return isMarried;
    }

    public void setMarried(boolean married) {
        isMarried = married;
    }

    public Person getObject() {
        return object;
    }

    public void setObject(Person object) {
        this.object = object;
    }
    public boolean Marryage() {
        if (!this.sex && this.getAge() >= 19)
        {return true;}
        if (this.sex && this.getAge() >= 20)
        {return true;}
        return false;
    }
    public static boolean marryWith(Person p1, Person p2) {
        if (p1.sex == p2.sex) {
            System.out.println("性别相同，无法结婚！！！");
            return false;
        }
        if (p1.isMarried != false || p2.isMarried != false) {
            System.out.println("已婚，不可结婚！！！");
            return false;
        }
        if (!p1.Marryage() || !p2.Marryage()) {
            System.out.println("未到法定年龄！！！");
            return false;
        }
        System.out.println(p1.name + "和" + p2.name + "符合条件，可以结婚");
        p1.object = p2;
        p2.object = p1;
        return true;
    }


    public Person(String name) {
        this.name = name;
    }

    public void study (String school){
        System.out.println(name+"在"+school+"学校学习");
    }
}
public class day3homework {
    public static void main(String[] args) {
        Person person1 = new Person("张三",true,20,false);
        Person person2 = new Person("李四",false,22,false);
        Person.marryWith(person1, person2);


        Person person=new Person("王五"){
            @Override
            public void study(String school) {
                System.out.println("请输入现在大几");
                int in=new Scanner(System.in).nextInt();
                if (in>4 || in<0)
                {
                    System.out.println("格式有误，重新运行！！");
                    return;
                }
                super.study("泉州职业技术大学");
                System.out.println("学习了"+in+"年");;
            }
        };
        person.study("");
    }
}

